<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 一级分类下的二级分类的数据爬取，核心代码，一级分类和二级分类名要下载商品数据循环里面，这样才能保证得到每个商品对应的分类id和名称一致
        // 一下为珠宝钟表分类一下的数据爬取代码
        // 聚鲨裂变上面数据
        let arr = [];
        let items = document.getElementsByClassName('top')[0].children;
        for (let i = 0; i < items.length; i++) {
            let obj = {};
            obj.cbid = 12;
            obj.cbname = '厨房用具';
            obj.cid = "";
            obj.cname = "";
            let item = items[i];
            obj.gurl = item.getElementsByClassName('img')[0].style.backgroundImage.slice(5, -2);
            obj.gtitle = item.getElementsByClassName('name')[0].innerText;
            arr.push(obj);
        }
        // 聚鲨列表中间数据
        let items2 = document.getElementsByClassName('list-content')
        let obj = {};
        for (let i = 0; i < items2.length; i++) {
            let item = items2[i];
            let items3 = item.getElementsByClassName('list')[0].children;
            for (let k = 0; k < items3.length; k++) {
                let obj = {};
                obj.cbid = 12;
                obj.cbname = '厨房用具';
                obj.cid = i + 1;
                obj.cname = item.getElementsByClassName('list-title')[0].children[0].innerText;
                let item2 = items3[k];
                obj.gurl = item2.getElementsByClassName('img')[0].src;
                obj.gtitle = item2.getElementsByClassName('name')[0].innerText;
                arr.push(obj);
            }
            arr.push(obj);
        }
        // 聚鲨列表下面数据
        let items5 = document.getElementsByClassName('brand-group-list')[0].children;
        let brand = document.getElementsByClassName('brand-group-title')[0].getElementsByClassName('text')[0].innerText;
        for (let i = 0; i < items5.length; i++) {
            let obj = {};
            obj.cbid = 12;
            obj.cbname = '厨房用具';
            obj.cid = items2.length + 1;
            obj.cname = brand;
            let item = items5[i];
            obj.gurl = item.style.backgroundImage.slice(5, -2)
            obj.gtitle = "";
            arr.push(obj);
        }
        // console.log(arr);
        let listdata = JSON.stringify(arr)
        console.log(listdata);

        // 推荐分类数据爬取
        let arr = [];
        let items5 = document.getElementsByClassName('tj-list')[0].children;
        let brand = document.getElementsByClassName('tj-list-title')[0].getElementsByClassName('text')[0].innerText;
        for (let i = 0; i < items5.length; i++) {
            let obj = {};
            obj.cbid = 1;
            obj.cbname = '推荐分类';
            obj.cid = 1;
            obj.cname = brand;
            let item = items5[i];
            obj.gurl = item.getElementsByClassName('img')[0].src;
            obj.gtitle =item.getElementsByClassName('name')[0].innerText;
            arr.push(obj);
        }
        // console.log(arr);
        let listdata = JSON.stringify(arr)
        console.log(listdata);

        // 推荐品牌数据爬取
        let arr = [];
        let items5 = document.getElementsByClassName('brand-group-list')[0].children;
        let brand = document.getElementsByClassName('brand-group-title')[0].getElementsByClassName('text')[0].innerText;
        for (let i = 0; i < items5.length; i++) {
            let obj = {};
            obj.cbid = 2;
            obj.cbname = '推荐品牌';
            obj.cid = 1;
            obj.cname = brand;
            let item = items5[i];
            obj.gurl = item.style.backgroundImage.slice(5, -2)
            obj.gtitle = "";
            arr.push(obj);
        }
        // console.log(arr);
        let listdata = JSON.stringify(arr)
        console.log(listdata);
    </script>

</body>

</html>